<template>
  <div>
    <div>
      <div>
        用户名<input type="text" v-model="emp.ename"> <br>
        性别<input type="radio" v-model="emp.esex" value="男"> 男
        <input type="radio" v-model="emp.esex" value="女">女 <br>
        工资<input type="text" v-model="emp.salary"> <br>
        密码<input type="text" v-model="emp.pwd"> <br>
        部门编号
        <select v-model="emp.dno" >
          <option :value="d.dno" v-for="d in depts">{{d.dname}}</option>
        </select>
        <br>
        生产日期<input type="date" v-model="emp.bornDate"> <br>
        <button @click="onSub">提交</button>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "InserEmp",
    data() {
      return {
        depts: [],
        emp:{
          ename:"",
          esex:"",
          salary:"",
          pwd:"",
          dno:101,
          bornDate:"2020-01-01"
        }
      }
    },
    methods:{
      onSub(){
        var vm = this;
        this.axios({
          url:"http://localhost:8081/emp/addEmp",
          method:"post",
          data:vm.emp
        }).then(x=>{
            alert(x.data);
        })
      }
    },
    mounted() {
      var vm= this;
      this.axios({
        url: "http://localhost:8081/dept/getAll",
        method: "get"
      }).then(x => {
          vm.depts=x.data;
      })
    }
  }
</script>

<style scoped>

</style>
